﻿/* Scripts for match history partial view */

$(function () {
    var masterHub = $.connection.masterHub;

    masterHub.client.updateLoggedInUsers = function (data) {

        // Clear any previous game displays.
        $(".singleMatch").remove();


        // Plot up new game displays.
        for(var i = 0; i<data.length; i++)
        {
            var playerNames = "-";
            for (var j = 0; j < data[i].playerUserProfiles.length; j++)
            {
                playerNames += "<a href='/Account/UserProfile/"+data[i].playerUserProfiles[j].UserId + "'>" + data[i].playerUserProfiles[j].UserName + "</a>-";
            }

           $("#recentMatches").append("<div class='singleMatch'><img src = /Images/" + data[i].gameTypeGameID + ".png></img> <ul>"
                               + "<li><b>Players</b> :</li> <li>" + playerNames + "</li>"
                               + "<li><b>Game Type</b> : " + data[i].gameType.name + "</li>"
                               + "<li><i>" + data[i].gameEnded + "</i></li>"
                               + "</ul></div>");
        }
    };

    $.connection.hub.start().done(function ()
    {
        masterHub.server.getLoggedInUsers();
    });

}
);

